package com.dnjn.happiness.oss.api.factory;

import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.oss.api.RemoteMinioService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.web.multipart.MultipartFile;

public class RemoteMinioFallbackFactory implements FallbackFactory<RemoteMinioService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteMinioFallbackFactory.class);
    @Override
    public RemoteMinioService create(Throwable throwable) {
        log.error("调用Minio服务失败：" + throwable.getMessage());
        return new RemoteMinioService() {
            @Override
            public AjaxResult uploadMinioCommonInnerApi(MultipartFile file, String source) throws Exception {
                return AjaxResult.error("调用Minion获取上传路径失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult uploadAvatarMinio(MultipartFile file, String source) throws Exception {
                return AjaxResult.error("调用Minion获取上传路径失败：{}" + throwable.getMessage());
            }
        };
    }
}
